/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validator;

import Model.UserBean;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author amkreuz
 */
@FacesValidator("Validator.RemoveSelf")
public class RemoveSelf implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            UserBean bean = (UserBean) FacesContext.getCurrentInstance().
                    getExternalContext().getSessionMap().get("userBean");
        if (value.toString().equals(bean.getUserName())) {
            FacesMessage msg = new FacesMessage("Cannot remove yourself. Try leave household");
            throw new ValidatorException(msg);
        }
    }
}
